﻿@model IniTechCaash.WebApplication.Models.JournalEntryDetailsViewModel
@using IniTechCaash.Domain.Entities

@{
    ViewBag.Title = "Details";
}

<h2>Journal Entry</h2>

<div>
    <h4>@Html.DisplayFor(model => model.CompositeId)</h4>
	<hr />
    <dl class="dl-horizontal">
        <dt>
            @Html.DisplayNameFor(model => model.CreatedBy)
        </dt>

        <dd>
            @Html.DisplayFor(model => model.CreatedBy)
        </dd>

        <dt>
            @Html.DisplayNameFor(model => model.CreatedDate)
        </dt>

        <dd>
            @Html.DisplayFor(model => model.CreatedDate)
        </dd>

        <dt>
            @Html.DisplayNameFor(model => model.LastModifiedBy)
        </dt>

        <dd>
            @Html.DisplayFor(model => model.LastModifiedBy)
        </dd>

        <dt>
            @Html.DisplayNameFor(model => model.LastModifiedDate)
        </dt>

        <dd>
            @Html.DisplayFor(model => model.LastModifiedDate)
        </dd>

        <dt>
            Is Posted
        </dt>

        <dd>
            @Html.DisplayFor(model => model.IsPosted)
        </dd>

        <dt>
            @Html.DisplayNameFor(model => model.SourceDocument)
        </dt>

        <dd>
            @if (Model.SourceDocument != null)
            {
                @Html.ActionLink(Model.SourceDocument, "SourceDocument", new { fileName = Model.Id + "_" + Model.SourceDocument });
            }
            else
            {
                <p>—</p>
            }
        </dd>
    </dl>
</div>
<h4>Lines</h4>
<hr />
<table class="table">
    <thead>
        <tr>
            <th>#</th>
            <th>Account</th>
            <th class="text-right">DR</th>
            <th class="text-right">CR</th>
            <th>Date</th>
            <th>Description</th>
        </tr>
    </thead>
    <tbody>
        @for (int i = 0; i < Model.Lines.Count; ++i)
        {
            <tr>
                <td>@(i + 1)</td>
                @if (Model.Lines[i].Side == NormalSide.Debit)
                {
                    <td>@Html.ActionLink(Model.Lines[i].Account.CompositeId, "Details", "FinanceAccount", new { id = Model.Lines[i].Account.Id }, null)</td>
                    <td class="text-right">@Html.DisplayFor(model => model.Lines[i].Amount)</td>
                    <td></td>
                }
                else
                {
                    <td class="credit-indent">@Html.ActionLink(Model.Lines[i].Account.CompositeId, "Details", "FinanceAccount", new { id = Model.Lines[i].Account.Id }, null)</td>
                    <td></td>
                    <td class="text-right">@Html.DisplayFor(model => model.Lines[i].Amount)</td>
                }
                <td>@Html.DisplayFor(model => model.Lines[i].Date)</td>
                <td>@Html.DisplayFor(model => model.Lines[i].Description)</td>
            </tr>
        }
    </tbody>
</table>
<hr />
@{
    Html.RenderPartial("_ActivityLogPartial", Model.ActivityLogs);  
}
<hr />
@if (Model.IsPosted)
{
    <p>
        @Html.ActionLink("Back to List", "Index")
    </p>
}
else if (User.IsInRole("Manager"))
{
    <p>
        @Html.ActionLink("Post", "Post", new { id = Model.Id }) |
        @Html.ActionLink("Edit", "Edit", new { id = Model.Id }) |
        @Html.ActionLink("Delete", "Delete", new { id = Model.Id }) |
        @Html.ActionLink("Back to List", "Index")
    </p>
}
else if (Model.CreatedBy == User.Identity.Name)
{
    <p>
        @Html.ActionLink("Edit", "Edit", new { id = Model.Id }) |
        @Html.ActionLink("Delete", "Delete", new { id = Model.Id }) |
        @Html.ActionLink("Back to List", "Index")
    </p>
}
else
{
    <p>
        @Html.ActionLink("Delete", "Delete", new { id = Model.Id }) |
        @Html.ActionLink("Back to List", "Index")
    </p>
}
